package com.yc.clouduser.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.clouduser.entity.User;
import com.yc.clouduser.mapper.UserMapper;
import com.yc.clouduser.service.IUserService;
import com.yc.vcode.bean.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzk
 * @since 2024-09-20
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public Result updatepwd(Integer uid, String oldPassword, String newPassword) {
        User user = userMapper.selectById(uid);
        String md5 = DigestUtils.md5DigestAsHex(oldPassword.getBytes());
        if(md5.equals(user.getPwd())){
            //验证成功
            md5 = DigestUtils.md5DigestAsHex(newPassword.getBytes());
            user.setPwd(md5);
            userMapper.updateById(user);
            return new Result(1, "修改成功", null);
        }
        return new Result(0, "旧密码错误", null);
    }

}
